<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    include_once '../connection/databaseHandler.php';
    include_once '../connection/sessionHandler.php';
    $database   = new DatabaseHandler();
    $session    = new SessionHandler();

    $username   = $session->username;
    $mode       = $_GET['mode'];

    // mengambil notifikasi
    $query      = "SELECT * FROM ".$database->t_notif." WHERE username='".$username."' AND status=0";
    $result     = $database->execQuery($query);
    $count      = mysql_num_rows($result);

    if ($mode=="num") {
        echo $count;
    }
    else {
        header("Content-type: text/xml");
        $xmlResponse = "<root>";
        $xmlResponse .= "<count>".$count."</count>";
        for ($i=0;$i<$count;$i++) {
            $xmlResponse .= "<message>".mysql_result($result, $i, $database->t_notif.".message")."</message>";
        }
        $xmlResponse .= "</root>";
        echo $xmlResponse;

        // memberi tanda notif sudah dibaca
        $query      = "UPDATE ".$database->t_notif." SET status=1 WHERE username='".$session->username."'";;
        $database->execQuery($query);
    }

?>
